package com.atguigu.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.atguigu.dao.MemberDao;
import com.atguigu.pojo.Member;
import com.atguigu.service.MemberService;
import com.atguigu.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

/**
 * MemberServiceImpl
 *
 * @Author: 马伟奇
 * @CreateTime: 2021-02-03
 * @Description:
 */
@Service(interfaceClass = MemberService.class)
@Transactional
public class MemberServiceImpl implements MemberService {

    @Autowired
    private MemberDao memberDao;

    @Override
    public Member findByTelephone(String telephone) {
        return memberDao.findByTelephone(telephone);
    }

    @Override
    public void add(Member member) {
        memberDao.add(member);
    }

    @Override
    public List<Integer> findMemberCountByMonth(List<String> months) {
        List<Integer> memeberCountList = new ArrayList<Integer>();
        for (String month : months) {
            // 找到每个月的最后一天
            // 1:31
            // 2:28
            // 4:30
            String regTime = DateUtils.getLastDayOfMonth(month);
            // 查询会员数据库 查询每个月的会员数量
            Integer memeberCount = memberDao.findMemberCountBeforeDate(regTime);
            memeberCountList.add(memeberCount);

        }


        return memeberCountList;
    }
}